package com.eos.business.service;

import java.util.List;
import java.util.Map;

import com.eos.common.tool.DaoAccessObjectPoolContextFactory;
import com.eos.orm.c3p0.dao.AbstractC3p0Dao;
import com.eos.orm.c3p0.dao.impl.ProductBrandDaoImpl;
import com.eos.orm.c3p0.dao.impl.ProductModelDaoImpl;
import com.eos.orm.c3p0.dao.impl.SysColourDaoImpl;
import com.eos.orm.c3p0.dao.impl.SysProductDaoImpl;
import com.eos.orm.mybatis.dao.ProductBrandMapper;
import com.eos.orm.mybatis.dao.ProductModelMapper;
import com.eos.orm.mybatis.dao.SysColourMapper;
import com.eos.orm.mybatis.dao.SysProductMapper;
import com.eos.orm.mybatis.model.ProductBrand;
import com.eos.orm.mybatis.model.ProductBrandExample;
import com.eos.orm.mybatis.model.ProductModel;
import com.eos.orm.mybatis.model.ProductModelExample;
import com.eos.orm.mybatis.model.SysColour;
import com.eos.orm.mybatis.model.SysColourExample;
import com.eos.orm.mybatis.model.SysProduct;
import com.eos.orm.mybatis.model.SysProductExample;
import com.hf.utils.PaginationBean;

public class SysProductBusinessService extends AbstractEosService<SysProduct>{
	private SysProductMapper productMapper =  (SysProductMapper)DaoAccessObjectPoolContextFactory
		.getInstaAccessObjectPoolContext().instanceDataAccessObject("SysProductMapper");
	private ProductBrandMapper proBrandMapper = (ProductBrandMapper) DaoAccessObjectPoolContextFactory
		.getInstaAccessObjectPoolContext().instanceDataAccessObject("ProductBrandMapper");
	private SysColourMapper colorMapper = (SysColourMapper) DaoAccessObjectPoolContextFactory
		.getInstaAccessObjectPoolContext().instanceDataAccessObject("SysColourMapper");
	private ProductModelMapper proModelMapper = (ProductModelMapper) DaoAccessObjectPoolContextFactory
		.getInstaAccessObjectPoolContext().instanceDataAccessObject("ProductModelMapper");
	private AbstractC3p0Dao<SysProduct> sysProductDao = (SysProductDaoImpl) DaoAccessObjectPoolContextFactory
		.getInstaAccessObjectPoolContext().instanceDataAccessObject("SysProductDao");
	private AbstractC3p0Dao<ProductBrand> proBrandDao = (ProductBrandDaoImpl) DaoAccessObjectPoolContextFactory
		.getInstaAccessObjectPoolContext().instanceDataAccessObject("ProductBrandDao");
	private AbstractC3p0Dao<ProductModel> proModelDao = (ProductModelDaoImpl) DaoAccessObjectPoolContextFactory
		.getInstaAccessObjectPoolContext().instanceDataAccessObject("ProductModelDao");
	private AbstractC3p0Dao<SysColour> colorDao = (SysColourDaoImpl) DaoAccessObjectPoolContextFactory
	.getInstaAccessObjectPoolContext().instanceDataAccessObject("SysColourDao");
	
	/**
	 * 获取品名信息
	 * @param sysProduct
	 * @return
	 */
	public List<SysProduct> getSysProductExample(SysProduct sysProduct){
		SysProductExample example = new SysProductExample();
		SysProductExample.Criteria cri = example.createCriteria();
		if(null != sysProduct.getProductName())
			cri.andProductNameEqualTo(sysProduct.getProductName());
		if(null != sysProduct.getId())
			cri.andIdEqualTo(sysProduct.getId());
		if(null != sysProduct.getDealFlag())
			cri.andDealFlagEqualTo(sysProduct.getDealFlag());
		if(null != sysProduct.getStatus())
			cri.andStatusEqualTo(sysProduct.getStatus());
		return productMapper.selectByExample(example);
	}
	
	/**
	 * 获取品名信息
	 * @param sysProductId 品名ID
	 * @return
	 */
	public SysProduct getSysProductPrimaryKey(int sysProductId){
		return productMapper.selectByPrimaryKey(sysProductId);
	}
	
	/**
	 * 保存品名信息
	 * @param prodcut
	 * @return
	 */
	public String saveSysProduct(SysProduct prodcut){
		return productMapper.insert(prodcut) == 0 ? "SUCCESS" : "FAIL";
	}
	
	/**
	 * 通过主键, 更新品名部分信息
	 * @param sysProduct
	 * @return
	 */
	public String updateSysProductPKSelective(SysProduct sysProduct){
		return productMapper.updateByPrimaryKeySelective(sysProduct)==0 ? "SUCCESS" : "FAIL";
	}
	
	/**
	 * 分页查询品名信息
	 * @param map
	 * @return
	 */
	public PaginationBean getSysProductList(Map<String, String> map){
		List<SysProduct> productList = sysProductDao.findPage(map);
		PaginationBean pageBean = sysProductDao.findBean(map);
		pageBean.setResultList(productList);
		return pageBean;
	}
	
	/**
	 * 根据不同条件筛选品牌信息
	 * @param proBrand
	 * @return
	 */
	public List<ProductBrand> getProductBrandExample(ProductBrand proBrand){
		ProductBrandExample example = new ProductBrandExample();
		ProductBrandExample.Criteria cri = example.createCriteria();
		if(null != proBrand.getBrandName())
			cri.andBrandNameEqualTo(proBrand.getBrandName());
		if(null != proBrand.getId())
			cri.andIdEqualTo(proBrand.getId());
		if(null != proBrand.getDealFlag())
			cri.andDealFlagEqualTo(proBrand.getDealFlag());
		if(null != proBrand.getStatus())
			cri.andStatusEqualTo(proBrand.getStatus());
		return proBrandMapper.selectByExample(example);
	}
	
	/**
	 * 保存品牌信息
	 * @param brand
	 * @return
	 */
	public String saveProductBrand(ProductBrand brand){
		return proBrandMapper.insert(brand)==0 ? "SUCCESS" : "FAIL";
	}
	
	/**
	 * 获取品牌信息
	 * @param brandId
	 * @return
	 */
	public ProductBrand getProductBrandPrimaryKey(int brandId){
		return proBrandMapper.selectByPrimaryKey(brandId);
	}
	
	/**
	 * 根据主键修改品牌部分信息
	 * @param brand
	 * @return
	 */
	public String updateProductBrandSelective(ProductBrand brand){
		return proBrandMapper.updateByPrimaryKeySelective(brand) == 0 ? "SUCCESS" : "FAIL";
	}
	
	/**
	 * 分页查询品牌信息
	 * @param map
	 * @return
	 */
	public PaginationBean getProductBrandList(Map<String, String> map){
		PaginationBean pageBean = proBrandDao.findBean(map);
		List<ProductBrand> proBrandList = proBrandDao.findPage(map);
		pageBean.setResultList(proBrandList);
		return pageBean;
	}
	
	/**
	 * 保存颜色信息
	 * @param color
	 * @return
	 */
	public String saveSysColor(SysColour color){
		return colorMapper.insert(color) == 0 ? "SUCCESS" : "FAIL";
	}
	
	/**
	 * 根据主键获取颜色信息
	 * @param colorId
	 * @return
	 */
	public SysColour getSysColorPrimaryKey(int colorId){
		return colorMapper.selectByPrimaryKey(colorId);
	}
	
	/**
	 * 根据不同条件, 筛选颜色信息
	 * @param color
	 * @return
	 */
	public List<SysColour> getSysColorExample(SysColour color){
		SysColourExample example = new SysColourExample();
		SysColourExample.Criteria cri = example.createCriteria();
		if(null != color.getColourName())
			cri.andColourNameEqualTo(color.getColourName());
		if(null != color.getDealFlag())
			cri.andDealFlagEqualTo(color.getDealFlag());
		if(null != color.getStatus())
			cri.andStatusEqualTo(color.getStatus());
		return colorMapper.selectByExample(example);
	}
	
	/**
	 * 选择更新颜色的部分信息
	 * @param color
	 * @return
	 */
	public String updateSysColorSelective(SysColour color){
		return colorMapper.updateByPrimaryKeySelective(color) == 0 ? "SUCCESS" : "FAIL";
	}
	
	/**
	 *分页获取颜色信息
	 * @return
	 */
	public PaginationBean getSysColorList(Map<String, String> map){
		PaginationBean pageBean = colorDao.findBean(map);
		List<SysColour> colorList = colorDao.findPage(map);
		pageBean.setResultList(colorList);
		return pageBean;
	}
	
	/**
	 * 根据不同条件筛选产品型号
	 * @param pm
	 * @return
	 */
	public List<ProductModel> getProductModelExample(ProductModel pm){
		ProductModelExample example = new ProductModelExample();
		ProductModelExample.Criteria cri = example.createCriteria();
		if(null != pm.getBrandId())
			cri.andBrandIdEqualTo(pm.getBrandId());
		if(null != pm.getDealFlag())
			cri.andDealFlagEqualTo(pm.getDealFlag());
		if(null != pm.getModelName())
			cri.andModelNameEqualTo(pm.getModelName());
		if(null != pm.getStatus())
			cri.andStatusEqualTo(pm.getStatus());
		return proModelMapper.selectByExample(example);
	}
	
	/**
	 * 保存产品型号信息
	 * @param pm
	 * @return
	 */
	public String saveProductModel(ProductModel pm){
		return proModelMapper.insert(pm) == 0 ? "SUCCESS" : "FAIL";
	}
	
	/**
	 * 根据主键ID获取对应的型号信息
	 * @param modelId
	 * @return
	 */
	public ProductModel getProductModelPrimaryKey(int modelId){
		return proModelMapper.selectByPrimaryKey(modelId);
	}
	
	/**
	 * 根据主键, 修改型号部分信息
	 * @param pm
	 * @return
	 */
	public String updateProductModelPKSelective(ProductModel pm){
		return proModelMapper.updateByPrimaryKeySelective(pm) ==0 ? "SUCCESS" : "FAIL";
	}
	
	/**
	 * 分页获取产品型号信息
	 * @param map
	 * @return
	 */
	public PaginationBean getProductModelList(Map<String, String> map){
		PaginationBean pageBean = proModelDao.findBean(map);
		List<ProductModel> modelList = proModelDao.findPage(map);
		pageBean.setResultList(modelList);
		return pageBean;
	}
}
